//
//  JYTBaseModel.m
//  JYT_IOS
//
//  Created by nxa-tankeke on 16/12/14.
//  Copyright © 2016年 nxa-yuanguoxiang. All rights reserved.
//

#import "JYTBaseModel.h"

@implementation JYTBaseModel

- (NSNumber *) toNumber:(id) param
{
    NSNumber *n = nil;
    
    if (param && [param isKindOfClass:[NSNumber class]]) {
        n = param;
    } else {
        n = [NSNumber numberWithInt:0];
    }
    
    return n;
}

- (NSDate *) toDate:(id) param
{
    NSNumber *n = [self toNumber:param];
    double d = n.doubleValue;
    return d > 0 ? [NSDate dateWithTimeIntervalSince1970: (d / 1000)] : nil;
}

- (NSInteger) toInteger:(id) param
{
    NSNumber *n = [self toNumber:param];
    
    return n.integerValue;
}


- (int) toInt:(id) param
{
    NSNumber *n = [self toNumber:param];
    return  n.intValue;
}

- (double) toDouble:(id) param
{
    NSNumber *n = [self toNumber:param];
    return n.doubleValue;
}

- (long) toLong:(id) param
{
    NSNumber *n = [self toNumber:param];
    return n.longValue;
}

- (NSString *) toString:(id) param
{
    NSString *s = nil;
    if ([param isKindOfClass:[NSString class]]) {
        s = param;
    }
    return s;
}

- (NSNumber *) dateToNumber: (NSDate *) date
{
    NSNumber *nm = nil;
    if (date) {
        nm = [NSNumber numberWithDouble:([date timeIntervalSince1970] * 1000)];
    } else {
        nm = [NSNumber numberWithInt:0];
    }
    
    return nm;
}


@end
